'''
import cv2
import numpy as np
 
img = cv2.imread("C:\\Users\\Administrator\\Pictures\\1.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

orb=cv2.ORB_create()

kp=orb.detect(gray,None)
kp,des=orb.compute(gray,kp)
img2=cv2.drawKeypoints(img,kp,None,(255,0,0),flags=0)

cv2.imshow("1",img2)
cv2.waitKey(10000)
'''
import cv2
import numpy as np
from matplotlib import pyplot as plt

home="./"

def initTarget(target):
    template = cv2.imread(target,0)
    return template

def FindTarget(src,target):
    img_rgb = cv2.imread(src)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)

    res = cv2.matchTemplate(img_gray,target,cv2.TM_CCOEFF_NORMED)

    threshold = 0.8

    loc = np.where( res >= threshold)
    findPos=list(zip(*loc[::-1]))
    if len(findPos)>0:
        return findPos[0]
    else:
        return (-1,-1)
    '''for pt in zip(*loc[::-1]):
        cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
    #cv2.imshow("1",img_rgb)
    #cv2.waitKey(0)
    cv2.imwrite(home+'\\res.png',img_rgb)
    return (-1,-1)'''
